package com.bum.api.core.service.process;

import org.apache.commons.lang.StringUtils;

import com.bum.api.core.exp.om.Metas;
import com.bum.api.core.exp.om.Params;
import com.bum.api.core.html.HtmlModel;
import com.bum.api.core.html.HtmlRender;

public class ApiProcess implements IApiProcess {
	HtmlRender	htmlRender;

	@Override
	public String process(String path, Params params, Metas metas) {
		if (htmlRender != null) {
			HtmlModel model = HtmlModel.get(metas);
			String[] parts = StringUtils.split(path, "/", 3);

			StringBuffer view = new StringBuffer(parts[0]).append("/").append(parts[0]).append("-");
			if (parts.length > 1) {
				view.append(parts[1]);
			} else {
				view.append("home");
			}
			return htmlRender.render(view.toString(), model);
		}

		return null;
	}

	public void setHtmlRender(HtmlRender htmlRender) {
		this.htmlRender = htmlRender;
	}

}
